#include "MutaCursor.h"
#include "QDebug"


MutaCursor::MutaCursor(qreal x1, qreal y2) :
    millis(0),
    ticks(0),
    beats(0),
    pixels(0),
    tempo(120.0),
    meterBeats(4),
    meterLength(4),
    ticksPerBeat(128),
    pixelsPerTick(0.25),
    millisPerBeat(((60.0/tempo))*1000),
    px(0),
    cursorPath(0,0,2,1280)
{

}
void MutaCursor::setX(qreal x)
{
    this->px = x;
    cursorPath.setX(px);
}

void MutaCursor::setPixels(qreal x)
{
    this->px = x;
    pixels = x;
    ticks = pixels/pixelsPerTick;
    beats = ticks/ticksPerBeat;
    millis = beats*millisPerBeat;
    cursorPath.setX(px);
}

qreal MutaCursor::x()
{
    return px;
}

qreal MutaCursor::y()
{
    return 0;
}


void MutaCursor::setTime(qreal delta)
{
    millis+=delta;
    beats = millis/millisPerBeat;
    ticks = beats*ticksPerBeat;
    pixels = ticks*pixelsPerTick;
    this->setX(pixels);
    //qDebug() << "millis" << millis;
    //qDebug() << "beats" << beats;
    //qDebug() << "ticks" << ticks;
    //qDebug() << "pixels" << pixels;
}

void MutaCursor::reset()
{
    millis = 0;
    beats = 0;
    ticks = 0;
    pixels = 0;
    this->setX(0);
}

void MutaCursor::setMeterBeats(int meterBeats)
{
    this->meterBeats = meterBeats;
}

void MutaCursor::setMeterLength(int meterLength)
{
    this->meterLength = meterLength;
}

void MutaCursor::setTempo(double tempo)
{
    this->tempo = tempo;
    millisPerBeat = (60.0/tempo)*1000;
    millis = beats*millisPerBeat;
}

QPainterPath MutaCursor::getCursorPath()
{
    return cursorPath.shape();
}
